export default class {
  constructor(send2Ue, listen2Ue, removeUeListener) {
    this.send2Ue = send2Ue;
    this.listen2Ue = listen2Ue;
    this.removeUeListener = removeUeListener;
    this.baseCmd = "/BP_DGBusiness";
  }
  active(type, cb) {
    let searchType = "";
    if (type === 0) {
      searchType = "单元";
      this.listen2Ue(`${this.baseCmd}/GetUnitID_CallBack`, cb);
    } else if (type === 1) {
      searchType = "地块";
      this.listen2Ue(`${this.baseCmd}/GetBlockID_CallBack`, cb);
    } else {
      return undefined;
    }
    // 清除测量
    this.send2Ue(`${this.baseCmd}/EnableClickElement`, {
      status: true,
      type: searchType,
    });
  }
  cancel(type) {
    let searchType = "";
    if (type === 0) {
      searchType = "单元";
      this.removeUeListener(`${this.baseCmd}/GetUnitID_CallBack`);
    } else if (type === 1) {
      searchType = "地块";
      this.removeUeListener(`${this.baseCmd}/GetBlockID_CallBack`);
    } else {
      return undefined;
    }
    // 清除测量
    this.send2Ue(`${this.baseCmd}/EnableClickElement`, {
      status: false,
      type: searchType,
    });
  }
  highlight(list) {
    // 非数组返回undefined
    if (!Array.isArray(list)) {
      return undefined;
    }
    this.send2Ue(`${this.baseCmd}/HLResultBlock`, {
      BlockIDs: list,
    });
  }
  cancelHighlight() {
    this.send2Ue(`${this.baseCmd}/UnHLResultBlock`, {});
  }
}
